﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.SharePoint;

namespace IntelligentDecisioning.SharePoint.Definition.Fields
{
    public class RichTextField: TextField
    {
        public RichTextMode Mode { get; set; }
        public bool AppendOnly { get; set; }

        public RichTextField()
        {
            Mode = RichTextMode.Compatible;
            Lines = 5;
            base.Type = SPFieldType.Note.ToString();
        }

        protected override void AddCustomFieldAttributes(XmlWriter xmlWriter)
        {
            base.AddCustomFieldAttributes(xmlWriter);

            xmlWriter.WriteAttributeString(DefinitionConstants.RICHTEXT_ATTRIBUTE, DefinitionConstants.TRUE);
            xmlWriter.WriteAttributeString(DefinitionConstants.RICHTEXTMODE_ATTRIBUTE, Mode.ToString());

            if (Mode == RichTextMode.FullHtml)
            {
                xmlWriter.WriteAttributeString(DefinitionConstants.ISOLATESTYLES_ATTRIBUTE, DefinitionConstants.TRUE);
            }

            if (AppendOnly)
            {
                xmlWriter.WriteAttributeString(DefinitionConstants.APPENDONLY_ATTRIBUTE, DefinitionConstants.TRUE);
            }
        }
    }

    public enum RichTextMode
    {
        Compatible,
        FullHtml,
        HtmlAsXml
    }
}
